import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:imperius_insights/entity/bugstats.dart';
import 'package:imperius_insights/modules/projects/viewmodels/project.dart';
import 'package:imperius_insights/treaty/dimensions.dart';
import 'package:imperius_insights/treaty/palette.dart';
import 'package:imperius_insights/treaty/strings.dart';
import 'package:imperius_insights/treaty/styles.dart';
import 'package:url_launcher/url_launcher.dart';

class QaStats extends StatelessWidget {
  final ProjectViewModel project;
  final IssuesClassification issuesClassification;

  QaStats(this.project, this.issuesClassification);

  @override
  Widget build(BuildContext context) {
    final qualityInQATesting = project.data.qualityInQATesting;
    return Material(
        elevation: 6,
        borderRadius: BorderRadius.circular(4),
        color: Colors.white,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                    decoration: BoxDecoration(color: palette.theme),
                    padding: EdgeInsets.symmetric(
                        horizontal: layoutDimensions.cardPaddingHorizontal,
                        vertical: 8),
                    child: Row(
                      children: <Widget>[
                        Expanded(
                          child: Text(Strings.quality_pmo_stats_qa_title,
                              style: styles.contentContrast),
                        )
                      ],
                    )),

                /// 测试进度
                Wrap(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.fromLTRB(
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVertical,
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVerticalHalf),
                      child: Text('Case数：${qualityInQATesting.caseTotal}',
                          style: styles.content),
                    ),
                    Container(
                      padding: EdgeInsets.fromLTRB(
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVertical,
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVerticalHalf),
                      child: Text(
                          '开发执行：${qualityInQATesting.caseExecuted} (${qualityInQATesting.rdExecutiveRate})',
                          style: styles.content),
                    ),
                    Container(
                      padding: EdgeInsets.fromLTRB(
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVertical,
                          layoutDimensions.cardPaddingHorizontal,
                          layoutDimensions.cardPaddingVerticalHalf),
                      child: Text(
                          'QA执行：${qualityInQATesting.notRdExecutiveCount} (${qualityInQATesting.notRdExecutiveRate})',
                          style: styles.content),
                    ),
                  ],
                ),
                Divider(thickness: 0.5, height: 0, color: palette.divider),

                /// 质量指标状态
                Container(
                  padding: EdgeInsets.fromLTRB(
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical,
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVerticalHalf),
                  child: Text(
                      'Bug率：${qualityInQATesting.bugRate}（${qualityInQATesting.bugTotal}/${qualityInQATesting.caseTotal}）',
                      style: styles.content),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical,
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical),
                  child: Text(
                      'Bug分布：P1 ${issuesClassification.p1Count}个，P2 ${issuesClassification.p2Count}个，P3 ${issuesClassification.p3Count}个，P4 ${issuesClassification.p4Count}个，UI展示及文案 ${issuesClassification.uiIssuesCount}个，优化建议 ${issuesClassification.suggestionCount}个',
                      style: styles.content),
                ),
                Divider(thickness: 0.5, height: 0, color: palette.divider),
                Container(
                  padding: EdgeInsets.fromLTRB(
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical,
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVerticalHalf),
                  child: Text(
                      '需解决问题数 ${issuesClassification.pendingToResolveCount}个',
                      style: styles.content),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical,
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical),
                  child: Text(
                      '需复测问题数 ${issuesClassification.pendingToVerifyCount}个',
                      style: styles.content),
                ),
                Divider(height: 1, color: Colors.grey[200]),
                Container(
                  padding: EdgeInsets.fromLTRB(
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical,
                      layoutDimensions.cardPaddingHorizontal,
                      layoutDimensions.cardPaddingVertical),
                  child: Text('Reopen数 ${issuesClassification.reopenedCount}个',
                      style: styles.content),
                ),
                Divider(thickness: 0.5, height: 0, color: palette.divider),

                /// 快捷入口
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                            border: Border(
                                right: BorderSide(
                                    width: 0.5, color: palette.divider))),
                        child: InkWell(
                          onTap: () => launch(project.jiraLink),
                          child: Center(
                            child: Container(
                              padding: EdgeInsets.all(
                                  layoutDimensions.cardPaddingAll),
                              child: Text('查看JIRA', style: styles.content),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                            border: Border(
                                right: BorderSide(
                                    width: 0.5, color: palette.divider))),
                        child: InkWell(
                          onTap: () => launch(project.bugsLink),
                          child: Center(
                            child: Container(
                              padding: EdgeInsets.all(
                                  layoutDimensions.cardPaddingAll),
                              child: Text('查看Bugs', style: styles.content),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
            Divider(thickness: 0.5, height: 0, color: palette.divider),
          ],
        ));
  }

  Widget buildLabelInfoArea(String text) {
    return Container(
      padding: EdgeInsets.fromLTRB(
          layoutDimensions.cardPaddingHorizontal,
          layoutDimensions.cardPaddingVerticalHalf,
          layoutDimensions.cardPaddingHorizontal,
          layoutDimensions.cardPaddingVertical),
      child: Text(text, style: styles.content),
    );
  }
}
